package com.kdgz.kdgz.controller;

import com.kdgz.kdgz.beans.Rule;
import com.kdgz.kdgz.sevice.RuleService;
import com.kdgz.kdgz.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author Veneno
 * @Desc
 * @date 2021/3/29
 */
@RestController
public class RuleController {
    @Autowired
    RuleService ruleService;

    /**
     * 获得规则
     * @return com.kdgz.kdgz.beans.Rule
     */
    @GetMapping("/rules")
    public Rule getRule(){
        return ruleService.selectRule();
    }

    /**
     * 更新规则
     * @param rule 规则对象
     * @return java.lang.Integer
     */
    @PutMapping("/rules")
    public Result updateRule(@RequestBody Rule rule) {
        System.out.println(rule);
        Integer integer=ruleService.updateRule(rule);
        if (integer != 0){
            return Result.success();
        }else {
            return Result.fail("更新失败！");
        }
    }
}
